home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5619 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  44 lines

  1. Path: news.iadfw.net!usenet
  2. From: alpet@airmail.net (bob)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: writing to .exe file
  5. Date: Tue, 20 Feb 1996 06:53:57 GMT
  6. Organization: customer of Internet America
  7. Message-ID: <4gbkak$d42@news-f.iadfw.net>
  8. References: <4g961o$gdr@ultra.sonic.net>
  9. NNTP-Posting-Host: dal12-27.ppp.iadfw.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Ted Rollheiser <trollhei@sonic.net> wrote:
  13.  
  14. >I would like  to save data ( a string ) from one run of a (dos) program 
  15. >to the next by writing it to the .exe file. does this sound doable?
  16.  
  17. Sure, programs do it all the time.  Important part is to be sure space
  18. is allocated for your string, and that you have some marker to find
  19. the string.  Do something like this:
  20.  
  21. struct blah
  22. {
  23.    char   marker[10]="!@#$%%$#@!";
  24.    char   comment[80];
  25. }
  26.  
  27. This allocats a structure in your .exe file.  When your program runs,
  28. open the file (your .exe) in binary mode and scan for the marker.
  29. When you find it, you know the next 80 bytes are yours to play with.
  30. Modify to your hearts content.  A side note is a good idea to *not*
  31. stop at the first occurence of your marker.  It might be a  fluke and
  32. some real code in your program may dup this marker if the you find is
  33. not yours, overwriting the next 80 bytes could be real bad.  So go
  34. ahead and scan the whole file to be sure it doesn't occur again.
  35.  
  36. Adam
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.